/**
 * PokerSeq.java created by zhangzhidong 
 * at 下午9:57:14 2016年10月12日
 */
package algorithm;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author zhangzhidong<br>
 * comment generated at 2016年10月12日下午9:57:14<br>
 * 
 */
public class PokerSeq {

	/**
	 * 下午9:57:14 2016年10月12日
	 * @param args
	 */
	private static final List<String> names = new ArrayList<String>(){{
		add("Perfect");
		System.out.println(names);
		
		
	}};
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		
		
		new PokerSeq().isContinuous(new int[]{1,0,0,5,0});

	}
	 
	
	 public boolean isContinuous(int [] numbers) {
			qsort(numbers,0,numbers.length-1);
	        int numOfZero = 0;
	        for(int i=0;i<numbers.length;i++){
	         	if(numbers[i]==0) numOfZero++;   
	        }
	        int small = numOfZero;
	        int big = numOfZero+1;
	        int numOfGap = 0;
	        for(;big<numbers.length;big++,small++){
				if(numbers[big] == numbers[small]) return false;
	            numOfGap += numbers[big] - numbers[small] - 1;
	        }
	        return numOfZero>=numOfGap;
	        
	    }
	    void qsort(int arr[],int start,int end){
	        if(start>=end) return;
	        int mid = part(arr,start,end);
	        qsort(arr,start,mid-1);
	        qsort(arr,mid+1,end);  
	    }
	    int part(int arr[],int start,int end){
	        if(start>=end) return start;
	        int temp  = arr[start];
	        int i = start;
	        int j = end;
	        while(i<j){
				while(i<j && arr[j]>temp){
	                j--;
	            }
	            if(j>i){
	                arr[i++] = arr[j];
	            }
	            while(i<j && arr[i]<temp){
	             	 i--;
	            }
	            if(j>i){
	                arr[j--] = arr[i];
	            }
	        }
	        arr[i] = temp;
	        return i;
	    }
	    
	    

}
